<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 控件数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\ReportPushService;
use common\service\WorkTimeRecordService;
use common\validate\ReportPush;
use support\ErrorCode;
use think\Request;

class ReportPushController extends VerifyController
{
    /**
     * @var WorkTimeRecordService
     */
    private $reportPushService;

    public function __construct()
    {
        parent::__construct();
        $this->reportPushService = ReportPushService::getInstance();
    }

    /**
     * 推送到不同的角色项目成员
     * @param Request $request
     * @return \think\Response
     */
    public function pushProjectRoleUserList(Request $request)
    {
        $param = $request->param();
        $time = $param['param']['time'] ?? time();
        $role = $param['param']['role'] ?? '';
        $projectId = $param['param']['project_id'] ?? 0;
        $stepCategoryRemark = $param['param']['step_category_remark'] ?? [];

        $validate = new ReportPush();
        foreach ($stepCategoryRemark as $dataItem) {
            $validate->scene('StepCategoryRemark');
            if (!$validate->check($dataItem)) {
                throw_strack_exception($validate->getError(), ErrorCode::REQUEST_PARAM_ERROR);
            }
        }

        $res = $this->reportPushService->pushProjectRoleUserList($time, $role, $projectId, $stepCategoryRemark);
        return json(success_response('', $res));
    }

    /**
     * 定时任务推送每日报表
     * @return \think\Response
     */
    public function pushEveryDayReportMsg()
    {
        $res = $this->reportPushService->pushEveryDayReportMsg();
        return json(success_response('', $res));
    }

}
